package com.hq.learnmybatisplus.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 性能分析插件  打印sql执行时间
 * @author hq
 */
@Configuration
public class PerformanceInterceptorConfig {

    /**
     * 只在开发和测试环境中才生效 性能分析
     * @return
     */
    @Bean
    //@Profile({"dev","test"})
    public PerformanceInterceptor PerformanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //格式化sql
        performanceInterceptor.setFormat(true);
        //SQL 执行最大时长，超过自动停止运行，有助于发现问题。
        //performanceInterceptor.setMaxTime(5L);
        //是否写入日志文件
        //performanceInterceptor.setWriteInLog(true);
        return performanceInterceptor;
    }
}
